package cn.myzqu.code.generator.domain;

import cn.myzqu.code.common.json.JSON;
import cn.myzqu.code.common.utils.StringUtils;

/**
 * 数据库表列信息
 * 
 * @author 的川
 */
public class ColumnInfo
{
    /** 字段名称 */
    private String columnName;

    /** 字段类型 */
    private String dataType;

    /** 列描述 */
    private String columnComment;
    
    /** 列配置 */
    private ColumnConfig configInfo;

    /** Java属性类型 */
    private String attrType;

    /** Java属性名称(第一个字母大写)，如：user_name => UserName */
    private String attrName;

    /** Java属性名称(第一个字母小写)，如：user_name => userName */
    private String attrname;

    public ColumnInfo() {
    }

    public ColumnInfo(String columnName, String dataType, String columnComment, ColumnConfig configInfo, String attrType, String attrName, String attrname) {
        this.columnName = columnName;
        this.dataType = dataType;
        this.columnComment = columnComment;
        this.configInfo = configInfo;
        this.attrType = attrType;
        this.attrName = attrName;
        this.attrname = attrname;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    public String getColumnComment() {
        return columnComment;
    }

    public ColumnConfig getConfigInfo() {
        return configInfo;
    }

    public void setConfigInfo(ColumnConfig configInfo) {
        this.configInfo = configInfo;
    }

    public String getAttrType() {
        return attrType;
    }

    public void setAttrType(String attrType) {
        this.attrType = attrType;
    }

    public String getAttrName() {
        return attrName;
    }

    public void setAttrName(String attrName) {
        this.attrName = attrName;
    }

    public String getAttrname() {
        return attrname;
    }

    public void setAttrname(String attrname) {
        this.attrname = attrname;
    }

    public void setColumnComment(String columnComment) throws Exception
    {
        // 根据列描述解析列的配置信息
        if (StringUtils.isNotEmpty(columnComment) && columnComment.startsWith("{"))
        {
            this.configInfo = JSON.unmarshal(columnComment, ColumnConfig.class);
            this.columnComment = configInfo.getTitle();
        }
        else
        {
            this.columnComment = columnComment;
        }
    }

}
